Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encryption component #11

Merged
merged 14 commits into from
Jul 1, 2021
Merged

Encryption component #11

merged 14 commits into from
Jul 1, 2021

Conversation

ccorcoveanu
Copy link
Contributor

@ccorcoveanu ccorcoveanu commented Jun 29, 2021

Added new component for EncryptedData.

It uses the same key derivation mechanism as the account keyfile (in fact, that was refactored to use EncryptedData under the hood which is more general-purpose).

Link to component description:
https://docs.google.com/document/d/1Xxb39JJkf8B9UzzQZd3KeOzL6nomoOxOyxKpxDKRgiE/edit#

andreibancioiu
andreibancioiu previously approved these changes Jun 29, 2021
Copy link
Contributor

@andreibancioiu andreibancioiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

import {v4 as uuidv4} from "uuid";
const crypto = require("crypto");

export class Randomness {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️ I confirm there's no change in the logic of this class (only move / refactor).

@@ -0,0 +1,36 @@
import scryptsy from "scryptsy";

export class ScryptKeyDerivationParams {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirm there's no change in logic - only movement & refactoring ✔️ (better cohesion now).

private static generateDerivedKey(password: Buffer, salt: Buffer, kdfparams: ScryptKeyDerivationParams): Buffer {
const derivedKey = scryptsy(password, salt, kdfparams.n, kdfparams.r, kdfparams.p, kdfparams.dklen);
return derivedKey;
static ecFromJSON(keyfileObject: any): EncryptedData {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the prefix ec mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a typo, should have been ed for "Encrypted Data"

@@ -0,0 +1,22 @@
import { assert } from "chai";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for this test.


const decipher = crypto.createDecipheriv(data.cipher, derivedKeyFirstHalf, iv);

return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the padding is still done in userWallet.ts.

I can confirm there's no change in logic - only refactoring ✔️


export class Encryptor {
public static encrypt(data: Buffer, password: string, randomness: Randomness = new Randomness()): EncryptedData {
const kdParams = new ScryptKeyDerivationParams();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirm the login here is the one from the previous constructor of UserWallet ✔️

@ccorcoveanu ccorcoveanu merged commit bfd87f9 into development Jul 1, 2021
@ccorcoveanu ccorcoveanu deleted the encryption-component branch July 1, 2021 12:57
andreibancioiu added a commit that referenced this pull request Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants